package app.netant.book.us23;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Us23Detail extends BaseDetail {

	public Us23Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.23us.us";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".main #centerm .bdsub #content dd h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("全文阅读");
			if(idx>0){
				title = title.substring(0,idx).trim();
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".main #centerm .bdsub #content dd div.fl table#at tbody tr");
		for(int i=0;i<parts.size();i++){
			Elements ths = parts.get(i).select("th");
			Elements tds = parts.get(i).select("td");
			for(int j=0;j<ths.size();j++){
				if(tds.size()>j){
					String tagName = ths.get(j).text().trim();
					String tagValue = tds.get(j).text().trim();
					System.out.println("【Tag】:"+tagName+"="+tagValue);
					this.entity.setTag(tagName, tagValue);
				}
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main #centerm .bdsub #content dd p");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("内容简介")>=0){
				String memo = parts.get(i+1).text();
				System.out.println("【Memo】:"+memo);
				this.entity.setNovelMemo(memo);
			}
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".main #centerm .bdsub #content dd div.fl p.btnlinks a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("TXT下载")>=0){
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
			}
		}
	}
	
	@Override
	public void analyseType() {
		
	}
	
	public static void main(String[] args) {
		Us23Detail detail = new Us23Detail("https://www.23us.us/book/30754.html");
		detail.test();
	}



}
